package com.example.chapter5.demos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.chapter5.demos.entity.Blog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogMapper  extends BaseMapper<Blog> {
    //查找数据库里面所有的博客数据
    @Select("select * from blog")
    List<Blog> selectAll();
    // 查询分页数据, 跳过前 offset 行，返回接下来的 limit 行数据
    @Select("select * from blog order by created_at desc limit #{limit} offset #{offset}")
    List<Blog> findBlogsByPage(@Param("offset") int offset, @Param("limit") int limit);

    //查询博客总数量
    @Select("select count(*) from blog")
    int countBlogs();
}